module.exports = app => {
    const { STRING, INTEGER, DATE, ENUM, TEXT } = app.Sequelize;
    var User = require('../model/user')

    const Follows = app.model.define('follows', {
        user_id: {
            type: INTEGER(20),
            allowNull: false,
            primaryKey: true,
            defaultValue: 0,
            comment: '用户id',
            // references: {
            //     model: 'user',
            //     key: 'id'
            // },
            onDelete: 'cascade',
            onUpdate: 'restrict', // 更新时操作
        },
        follower_id: {
            type: INTEGER(20),
            allowNull: false,
            primaryKey: true,
            defaultValue: 0,
            comment: '关注用户id',
            // references: {
            //     model: 'user',
            //     key: 'id'
            // },
            onDelete: 'cascade',
            onUpdate: 'restrict', // 更新时操作
        },
        created_time: {
            type:DATE,
            get(){ 
                return app.formatTime(this.getDataValue('created_time'))
            }
        },
        updated_time: DATE
    });

    Follows.associate = function(){
        Follows.belongsTo(app.model.User,{as:'fol',foreignKey:'follower_id',targetKey:'id'});
        Follows.belongsTo(app.model.User,{as:'fan',foreignKey:'user_id',targetKey:'id'});
    };

    return Follows;
};